﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SBACN.WebSite.Code;
using System.Linq.Expressions;
using SBACN.WebSite.Models;

namespace SBACN.WebSite
{
	public partial class Search : BasePage
	{
		protected string Q
		{
			get
			{
				return Request.QueryString["q"];
			}
		}

		protected void Page_Load(object sender, EventArgs e)
		{
			BindData(1);

		}

		protected void BindData(int pageIndex)
		{
			// news media council
			string q = Request.QueryString["q"];

			int records = 0;
			if (!string.IsNullOrWhiteSpace(q))
			{
				Expression<Func<View_Search, bool>> f = (p => p.Title.Contains(q) || p.Content.Contains(q) || p.Summary.Contains(q));

				Expression<Func<View_Search, DateTime>> order = (c => c.CreateDate);
				var resultN = DAL.DALHelper.Instance.GetList<View_Search, DateTime>(f, order, false, this.Pager1.PageSize, pageIndex, out records);

				if (resultN.Count > 0)
				{
					this.list.DataSource = resultN;
					this.list.DataBind();
					this.Pager1.RecordCount = records;
					this.Pager1.InitControl();
				}
				else
				{
					this.Msg.Visible = true;
				}
			}
			else
			{
				this.Msg.Visible = true;
			}


		}

		protected void BindSelectedPageIndexChanged(int pageIndex, int nextPage)
		{
			BindData(nextPage);
		}

		protected string Url(string code, string id)
		{
			if (string.IsNullOrWhiteSpace(code))
				return "#";
			string s;
			switch (code)
			{
				case "00020004"://媒体报道
					s = "/GuildDynamic/MediaShow.aspx?st=" + code + "&id=" + id;
					break;
				case "00010004"://理事会
					s = "/CouncilDList/ComDetail.aspx?st=" + code + "&id=" + id;
					break;
				case "00020004_1"://媒体活动
					s = "/GuildDynamic/MediaList.aspx?st=00020004&id=" + id;
					break;
				default:
					s = "/ContentDL/ComDetail.aspx?st=" + code + "&id=" + id;
					break;
			}
			return s;
		}

		protected string ColorF(string Con)
		{
			if (!string.IsNullOrWhiteSpace(Con))
			{
				if (!string.IsNullOrWhiteSpace(this.Q))
				{
					string S = "<span style='color:red' >" + this.Q + "</span>";
					string C = Con.Replace(this.Q, S);
					return C;
				}
				else
				{
					return Con;
				}
			}
			else
			{
				return "";
			}

		}

	}
}